package com.tecode.service.impl;

import com.tecode.bean.Favorite;
import com.tecode.mapper.FavoriteMapper;
import com.tecode.mapper.FavotiteMusicMapper;
import com.tecode.service.FavoriteService;
import com.tecode.service.MusicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2019/4/10.
 */
@Service
public class FavoriteServiceImpl implements FavoriteService {
    @Autowired
    private FavoriteMapper favoriteMapper;
    @Autowired
    private MusicService musicService;
    @Autowired
    private FavotiteMusicMapper favotiteMusicMapper;

    @Override
    public List getTypeListByUserId(Integer userId) {
        return favoriteMapper.getTypeListByUserId(userId);
    }

    @Override
    public Favorite getFavoriteById(Integer favoriteId) {
        return favoriteMapper.getFavoriteById(favoriteId);
    }

    @Override
    public int save(Favorite favorite) {
        return favoriteMapper.editSave(favorite);
    }

    @Transactional
    @Override
    public int del(Integer favoriteId) {
//        Favorite favorite = getFavoriteById(favoriteId);
//        List musicIds = favotiteMusicMapper.getMusicIds(favoriteId);
//        int i = favotiteMusicMapper.deleteFavoriteMusic(favoriteId);
//        musicService.del(musicIds);
        return favoriteMapper.deleteFavorite(favoriteId);
    }

    @Override
    public List getFavoritesById(Integer favoriteId) {
        return favoriteMapper.getFavoritesById(favoriteId);
    }

    @Override
    public List<String> selectSheetNameLisetByUserId(Integer userId) {
        return favoriteMapper.selectSheetNameLisetByUserId(userId);
    }

    @Override
    public int cancelCollection(Integer userId, Integer musicId) {
        return favoriteMapper.cancelCollection(userId,musicId);
    }

    @Override
    public int songCollection(Integer userId, Integer musicId, String name) {
        return favoriteMapper.songCollection(userId,musicId,name);
    }

    @Override
    public int newCollectionSheet(Integer userId, String name, Date creatTime) {
        return favoriteMapper.newCollectionSheet(userId,name,creatTime);
    }
}
